﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace Server
{
    public class ConvertEntityModel
    {
        public static RssFeed ToRssFeed(ChannelEntity c)
        {
            if (c == null)
                return null;
            RssFeed chan = new RssFeed();
            chan.date = c.date;
            chan.description = c.description;
            chan.id = c.id;
            chan.link = c.link;
            chan.@public = c.@public;
            chan.title = c.title;
            chan.url = c.url;
            return chan;
        }

        public static RssFeedItem ToRssFeedItem(ItemEntity i, UserEntity u)
        {
            if (i == null || u == null)
                return null;
            RssFeedItem item = new RssFeedItem();
            item.date = i.date;
            item.description = i.description;
            item.id = i.id;
            item.link = i.link;
            item.title = i.title;
            item.read = false;
            foreach (ItemStateEntity e in i.itemStates)
                if (e.user == u.id)
                    item.read = e.readState;
            return item;
        }
    }
}